package com.zlp.spring.init.strategy;

import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

/**
 * 策略工厂(组装和调用)
 * @date: 2022/2/23 19:29
 */
@Component
public class ReportStrategyFactory {

    private Map<String, Object> REPORT_STRATEGY_MAP = new HashMap<>(10);

    @Resource(name = "mciReportStrategy")
    private ReportStrategy mciReportStrategy;

    @Resource(name = "pdReportStrategy")
    private ReportStrategy pdReportStrategy;

    @PostConstruct
    public void initStrategyFactory() {
        REPORT_STRATEGY_MAP.put(DrugCode.MCI, mciReportStrategy);
        REPORT_STRATEGY_MAP.put(DrugCode.PD, pdReportStrategy);
    }

    public interface DrugCode {

        String MCI = "MCI";
        String PD = "PD";
    }

    public ReportStrategy getReportStrategy(String drugCode) {

        ReportStrategy reportStrategy = (ReportStrategy) REPORT_STRATEGY_MAP.get(drugCode);
        return Objects.isNull(drugCode) ? mciReportStrategy : reportStrategy;
    }
}
